package qlsl.androiddesign.view.subview.activityview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.qlsl.androiddesign.kuaiwa.R;

import android.content.Intent;
import android.view.View;
import android.widget.ListView;
import qlsl.androiddesign.activity.subactivity.CarTypeActivity;
import qlsl.androiddesign.activity.subactivity.CarTypeSecondActivity;
import qlsl.androiddesign.adapter.subadapter.CarTypeAdapter;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 评估分类页<br/>
 * 需要传入的键：<br/>
 * 传入的值类型： <br/>
 * 传入的值含义：<br/>
 * 是否必传 ：
 */
public class CarTypeView extends FunctionView<CarTypeActivity> {

	private ListView listView;

	public CarTypeView(CarTypeActivity activity) {
		super(activity);
		setContentView(R.layout.activity_publish_type);
	}

	protected void initView(View view) {
		setTitle("分类");
		listView = findViewById(R.id.listView);
		listView.setEmptyView(findViewById(R.id.tv_empty));
	}

	protected void initData() {
		setListViewData();
	}

	protected void initListener() {

	}

	public <T> void showData(T... t) {

	}

	public <T> void showNoData(T... t) {

	}

	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.list_item:
			doClickListItem(view);
			break;
		}
	}

	@SuppressWarnings("rawtypes")
	private void doClickListItem(View view) {
		int position = listView.getPositionForView(view);
		String title = (String) ((HashMap) listView.getAdapter().getItem(position)).get("text");
		Intent intent = new Intent(activity, CarTypeSecondActivity.class);
		intent.putExtra("title", title);
		intent.putExtra("position", position);
		startActivityForResult(intent, 0);
	}

	private void setListViewData() {
		String[] texts = new String[] { "国产", "进口" };
		List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
		for (int index = 0; index < texts.length; index++) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("text", texts[index]);
			list.add(map);
		}
		CarTypeAdapter adapter = new CarTypeAdapter(activity, list);
		listView.setAdapter(adapter);

	}

	public void onActivityResult(int arg0, int arg1, Intent intent) {
		if (intent != null) {
			activity.setResult(0, intent);
			activity.finish();
		}
	}

}
